package cn.zhf.shop.controller;

import cn.zhf.shop.entity.Message;
import cn.zhf.shop.entity.Stage;
import cn.zhf.shop.service.StageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "分期支付模块")
@RequestMapping("/api/stage/")
public class StageController {

    @Resource
    private StageService stageService;

    @ApiOperation(value = "新建分期支付")
    @PostMapping("/")
    public Message<?> insert(Stage s){
        return stageService.insert(s);
    }

    @ApiOperation(value = "通过orderId获取订单")
    @GetMapping("/orderId")
    public Message<Stage> getStageByOrderId(String orderId){
        return stageService.getStageByOrderId(orderId);
    }

    @ApiOperation(value = "通过state获取订单信息")
    @GetMapping("/state")
    public Message<List<Stage>> getStageByState(Integer state){
        return stageService.getStageByState(state);
    }

    @PutMapping(value = "/adult")
    @ApiOperation(value = "审核通过分期")
    public Message<?> applyStage(String orderId,Integer state){
        return stageService.updateState(orderId,state);
    }

    @GetMapping("/all")
    @ApiOperation(value = "获取所有")
    public Message<List<Stage>> getAll(){
        return stageService.getAllStage();
    }

}
